package com.example.myapplication;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class myadapter extends BaseAdapter {
    Context context;
    List<Map<String ,Object>> list;
    public myadapter (Context context,List<Map<String ,Object>> list){
        this.context=context;
        this.list=list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        viewHolder holder=new viewHolder();
        Map<String,Object> map = list.get(position);
            switch(getItemViewType(position)){
                case 0:
                    convertView = View.inflate(context,R.layout.layout,null);
                    holder.text = convertView.findViewById(R.id.text1);
                    holder.text.setText(map.get("data").toString());
                    break;
                case 1:
                    convertView = View.inflate(context,R.layout.layout2,null);
                    holder.text = convertView.findViewById(R.id.text1);
                    holder.text.setText(map.get("data").toString());
                    break;
        }
        return convertView;
    }
    public int getItemViewType(int position){
        super.getItemViewType(position);
        if((Boolean) list.get(position).get("flag")){
            return 0;
        }else{
            return 1;
        }
    }

    public int getViewTypeCount(){
//        super.getViewTypeCount();
        return 2;
    }

    public class viewHolder{
        TextView text;
    }

}
